<template>
  <el-container>
    <el-aside width="200px">
      <el-row class="tac">
        <el-col :span="22">
          <h3>学生管理系统</h3>
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
          >
            <el-sub-menu index="1" @click="sy">
              <template #title>
                <el-icon><location /></el-icon>
                <span>首页</span>
              </template>
              <el-menu-item-group title="">
                <el-menu-item index="1-1">条形图</el-menu-item>
              </el-menu-item-group>
            </el-sub-menu>
            <el-menu-item index="2" @click="xs">
              <el-icon><icon-menu /></el-icon>
              <span>学生信息</span>
            </el-menu-item>
            <el-menu-item index="3" @click="kc">
              <el-icon><document /></el-icon>
              <span>课程信息</span>
            </el-menu-item>
            <el-menu-item index="4" @click="tx">
              <el-icon><setting /></el-icon>
              <span>统计</span>
            </el-menu-item>
          </el-menu>
        </el-col>
      </el-row>
    </el-aside>
    <el-container>
      <el-header></el-header>
      <el-main>
        <div id="main11" style="width: 100%; height: 600px"></div>
        <div id="main12" style="width: 100%; height: 600px"></div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import * as echarts from "echarts";

import { defineComponent } from "vue";
import {
  Location,
  Document,
  Menu as IconMenu,
  Setting,
} from "@element-plus/icons";

export default defineComponent({
  name: "tiao",
  components: {
    Location,
    Document,
    Setting,
    IconMenu,
  },
  data() {
    return {
      mockindex: 0,
      mockdata: [
        [200, 100, 25, 80, 25, 218, 135],
        [210, 80, 25, 25, 218, 135, 147],
        [110, 170, 25, 218, 25, 218, 135],
        [187, 105, 25, 218, 135, 147, 260],
        [90, 60, 25, 105, 25, 218, 135],
      ],
    };
  },
  // setup() {
  //   const handleOpen = (key, keyPath) => {
  //     console.log(key, keyPath);
  //   };
  //   const handleClose = (key, keyPath) => {
  //     console.log(key, keyPath);
  //   };
  //   return {
  //     handleOpen,
  //     handleClose,
  //   };
  // },
  beforeDestory(){
      clearInterval(this.iniLine);
      clearInterval(this.tiaotu);
    },
  mounted() {
    let _this = this;
    setInterval(() => {
      _this.iniLine(_this.mockdata[_this.mockindex]);
    }, 1000);
    setInterval(() => {
      _this.tiaotu(_this.mockdata[_this.mockindex]);
    }, 1000);
  },
  methods: {
    tiaotu(data) {
      this.mockindex =
        this.mockindex < this.mockdata.length ? this.mockindex + 1 : 0;
      var chartDom = document.getElementById("main12");
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        xAxis: {
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: data,
            type: "bar",
            showBackground: true,
            backgroundStyle: {
              color: "rgba(180, 180, 180, 0.2)",
            },
          },
        ],
      };
      option && myChart.setOption(option);
    },
    random(max,min){
      return Math.floor(Math.random() * (max-min))+min;
    },
    iniLine() {
      let data=[];
      for(let i=1; i<=7; i++){
        let a=this.random(70,200);
        data.push(a);
      }
      this.mockindex =
        this.mockindex < this.mockdata.length ? this.mockindex + 1 : 0;
      var chartDom = document.getElementById("main11");
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        xAxis: {
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: data,
            type: "line",
          },
        ],
      };
      option && myChart.setOption(option);
    },
    sy(row) {
      this.$router.push({ name: "zy", params: { row: JSON.stringify(row) } });
    },
    xs(row) {
      this.$router.push({ name: "xs", params: { row: JSON.stringify(row) } });
    },
    tx(row) {
      this.$router.push({ name: "tiao", params: { row: JSON.stringify(row) } });
    },
    kc(row) {
      this.$router.push({ name: "kc", params: { row: JSON.stringify(row) } });
    },
  },
});
</script>

<style >
.el-breadcrumb__inner a,
.el-breadcrumb__inner.is-link {
  color: #fff;
}
.tac {
  text-align: center;
}
.el-menu-vertical-demo {
  width: 200px;
}
.el-container {
  height: 960px;
}
body {
  margin: 0;
  padding: 0;
}
.el-header,
.el-footer {
  background-color: #333333;
  color: var(--el-text-color-primary);
  text-align: center;
  line-height: 60px;
}

.el-aside {
  color: var(--el-text-color-primary);
  text-align: center;
}

.el-main {
  background-color: #e9eef3;
  color: var(--el-text-color-primary);
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>